package com.jaydenxiao.common.base;


import com.jaydenxiao.common.baseapp.BaseApplication;
import com.jaydenxiao.common.basebean.APIData;
import com.jaydenxiao.common.commonutils.AndroidUtil;
import com.jaydenxiao.common.commonutils.DeviceUtil;
import com.jaydenxiao.common.commonutils.JsonUtils;
import com.jaydenxiao.common.commonutils.TLHttpUtil;

/**
 * des:baseModel
 * Created by zsq
 * on 2016.12.14:50
 */
public abstract class BaseModel {
    public String initApiData(String method,String requestData,boolean isEncrypt,String token){
        APIData apiData=new APIData();
        if (isEncrypt) {
//            LogUtils.logd(context.getClass().getSimpleName() + "request Data = ", requestData);
            requestData = TLHttpUtil.e(requestData);
        }
        apiData.setD(requestData);//业务数据JSON格式
        apiData.setM(method);//请求的方法名
        apiData.setV(AndroidUtil.getVersionCode(BaseApplication.getAppContext()));//手机客户端版本号 getPackageInfo(context).versionCode
        apiData.setDID(DeviceUtil.getDeviceId(BaseApplication.getAppContext()));//手机设备ID
        apiData.setG(TLHttpUtil.r(BaseApplication.getAppContext()));//请求随机ID
        apiData.setIE(isEncrypt);//方法是否需要加密
        apiData.setE(1);//加密版本号
        if (token != null) {
            apiData.setT(token);
        }
        apiData.setTS(System.currentTimeMillis());//时间戳，系统时间的秒值,同个应用的不同api请求的time值应该是递增的, 用于防replay攻击
        apiData.setP(1);//1 Android

        return JsonUtils.toJson(apiData);
    }

    protected void resultCodeState(int code){


    }
}
